include("shared.lua")
include("ranks.lua")

local fileQueue = {} //Files for the client to include
for k,v in pairs(file.Find("../lua/plugins/*.lua")) do
	AddCSLuaFile("plugins/" .. v)
	include("plugins/" .. v)
	table.insert(fileQueue, tostring("plugins/" .. v))
end

hook.Add("PlayerAuthed", "SendPluginQueue", function(pl)
	for k,v in pairs(fileQueue) do
		pl:SendLua("include('" .. v .. "')")
	end
end)

function OpenKontrolMenu(pl, cmd, args)
	if !pl:KAdmin() && !pl:KModerator() then return end
	
	pl:SendLua("kontrolMenu()")
end
concommand.Add("sv_kontrol_menu", OpenKontrolMenu)

function OpenKontrolOnChat(pl, text, teamonly)
	if !pl:KAdmin() && !pl:KModerator() then return end
	
	if text == "!" then
		pl:SendLua("kontrolMenu()")
		return false
	end
end
hook.Add("PlayerSay", "OpenKontrolOnChat", OpenKontrolOnChat)

function KontrolMakeOwner(pl, cmd, args)
	if pl:IsPlayer() then return end

	local name = args[1]
	for k,v in pairs(player.GetAll()) do
		if v:Name() == name then
			v:SetRank("owner")
			break
		end
	end
end
concommand.Add("kontrol_owner", KontrolMakeOwner)